// 持久化插件
const KEY = 'VUEX:STATE'
export default (store) => {

    const state = JSON.parse(localStorage.getItem(KEY))
    if (state) {
        store.replaceState(state)
    }

    // 订阅 store 的 mutation;api=> https://vuex.vuejs.org/zh/api/#subscribe
    store.subscribe((mutation, state) => {
        localStorage.setItem(KEY, JSON.stringify(store.state))
    })

}